﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>权限表添加</title>
    <script src="https://cdn.staticfile.org/layui/2.8.12/layui.min.js"></script>
    <link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.8.12/css/layui.min.css">
</head>

<body>
    <form class="layui-form" id="permissionForm" style="width: 350px">
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:auto">权限名称</label>
            <div class="layui-input-block">
                <input type="text" name="menuName" required lay-verify="required" placeholder="请输入权限名称"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:auto">URL地址</label>
            <div class="layui-input-block">
                <input type="text" name="url" required lay-verify="required" placeholder="请输入URL地址"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:auto">父级菜单</label>
            <div class="layui-input-block">
                <select name="pId" lay-verify="required">
                    <!-- 这里可以通过 AJAX 请求动态加载父级菜单选项 -->
                    <option value="">请选择父级菜单</option>
                    <option value="1">顶级菜单</option>
                    <option value="2">用户管理</option>
                    <option value="3">角色管理</option>
                    <option value="4">权限/菜单管理</option>
                    <option value="5">部门管理</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:auto">创建人</label>
            <div class="layui-input-block">
                <input type="text" name="createName" required lay-verify="required" placeholder="请输入创建人"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="addPermission">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script>
        layui.use(['form', 'layer'], function () {
            var form = layui.form;
            var layer = layui.layer;

            form.on('submit(addPermission)', function (data) {
                // 发送 Ajax 请求
                $.ajax({
                    url: 'https://localhost:7272/api/Message/AddMenu',
                    //url: "@ViewBag.BaseUrl/T6/Message/AddMenu",
                    type:'POST',
                    contentType:'application/json',
                    data:JSON.stringify(data.field),
                    dataType:'json',
                    success: function (res) {
                        if (res.code === 212) {
                            layer.msg('添加成功');
                            $('#permissionForm')[0].reset();
                        } else {
                            layer.msg(res.msg);
                        }
                    },
                    error: function () {
                        layer.msg('请求出错，请稍后重试');
                    }
                });
                return false;
            });
        });
    </script>
</body>

</html>    